<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const toMoney = (
        money: number | string = 0,
        config = {
            accuracy: 3,
            isCover: false,
        }
    ) => {
        const defaultConfig = {
            accuracy: 3,
            isCover: false,
        };
        const { accuracy, isCover } = Object.assign(defaultConfig, config);
        money = parseFloat(money + "");
        if (isNaN(money)) {
            return "";
        } else {
            const _accuracy = Math.pow(10, accuracy);
            const _count = Math.trunc(money * _accuracy) / _accuracy;
            return isCover ? _count.toFixed(accuracy) : _count + "";
        }
    };
    console.log(toMoney(0, { accuracy: 3, isCover: true}));
    console.log(toMoney("qww033", { accuracy: 3, isCover: true}));
    // console.log(moneyFormat(222.5158));
    // console.log(moneyFormat(222.5));
    // console.log(moneyFormat(222.518).toFixed(3));
    // console.log(moneyFormat(222.519).toFixed(3));
    // console.log(moneyFormat(222.51).toFixed(3));
    // console.log(moneyFormat(222.5158).toFixed(3));
    // console.log(moneyFormat(222.5).toFixed(3));
</script>
</body>
</html>
